#include <stdio.h>
#include <stdlib.h>

typedef struct SeqNode *SeqPtr;
struct SeqNode {
    int *array; /* 存储数据的数组 */
    int n; /* 数组的大小 */
    int max_sum; /* 最大和 */
    int start, finish; /*最大连续子序列左右两端点的数组下标 */
};

/* 算法1-8：连续子序列最大和的O(n^2)算法 MaxSubsequenceSum2(s) */
int MaxSubsequenceSum2(SeqPtr s) {
    int i, j, this_sum;

    s->max_sum = 0;
    s->start = s->finish = -1;
    for (i = 0; i < s->n; i++) { /*当前子序列的起始位置*/
        this_sum = 0;
        for (j = i; j < s->n; j++) { /*当前子序列的终止位置*/
            this_sum += s->array[j]; /* 计算当前子序列的和 */
            if (this_sum > s->max_sum) { /*若当前和更大*/
                s->max_sum = this_sum; /* 更新最大和 */
                s->start = i; /*更新最大连续子序列起始位置*/
                s->finish = j; /*更新最大连续子序列终止位置*/
            }
        }
    }
    return s->max_sum;
}
/* 算法1-8 结束 */

int main(void) {
    int i;
    SeqPtr s;

    s = (SeqPtr)malloc(sizeof(struct SeqNode));
    scanf("%d", &s->n);
    s->array = (int *)malloc(sizeof(int) * s->n);
    for (i = 0; i < s->n; i++) {
        scanf("%d", &s->array[i]);
    }
    printf("%d\n", MaxSubsequenceSum2(s));
    printf("%d %d\n", s->start, s->finish);
    return 0;
}